﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace VisionCloud.Api.Common
{
    /// <summary>
    /// Http无权限403结果
    /// </summary>
    public class HttpFobitResult : ActionResult
    {
        /// <summary>
        /// 状态描述
        /// </summary>
        public string StatusDescription { get; set; }

        /// <summary>
        /// 状态代码
        /// </summary>
        public int StatusCode { get; set; } = 403;

        /// <summary>
        /// 状态结果
        /// </summary>
        public HttpFobitResult()
        { }

        /// <summary>
        /// 状态结果
        /// </summary>
        /// <param name="statusDescription"></param>
        public HttpFobitResult(string statusDescription)
        {
            StatusDescription = statusDescription;
        }

        /// <summary>
        /// 返回执行结果
        /// </summary>
        /// <param name="context"></param>
        public override void ExecuteResult(ActionContext context)
        {
            context.HttpContext.Response.StatusCode = StatusCode;
            if (!string.IsNullOrWhiteSpace(this.StatusDescription))
            {
                context.HttpContext.Response.WriteAsync(this.StatusDescription);
            }
        }
    }
}